#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include<QPainter>
#include <QMainWindow>
#include<QPen>
#include<math.h>
#include<QDebug>
#include<QBrush>
#include <QTimer>
#include "fmod.h"
#include "fmod_errors.h"
#include "CurvePlot.h"
#include <QVector>
#include <QStringList>
#include <QPoint>
#include "ui_Buttonl.h"
#include "Buttonl.h"
#include "Buttond.h"
#include "ui_Buttond.h"
#include "add_target.h"
#include "ui_add_target.h"
namespace Ui {
class MainWindow;
}
typedef struct info
{
    int id;         //编号
    int direction;  //方位
    int speed;      //速度
    int Slidervalue;//比例尺
    int color;      //目标颜色
    double x;       //当前X坐标
    double y;       //当前Y坐标

}info_t;

typedef struct data_d
{
    int danger;     //危险等级
    int stardir;    //起始方位
    int enddir;     //结束方位
    int near;       //近界
    int far;        //远界
    QString info;   //警告信息
}data_d;

typedef struct data_l
{
    int dir;        //方向
    int dis;        //距离
}data_l;

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();
    void paintEvent(QPaintEvent *event);
protected:
    void mouseMoveEvent(QMouseEvent *event);
    double get_distance(QPoint point);
private:
    Ui::MainWindow *ui;
    QPoint center;
    Buttond* buttond;
    Buttonl* buttonl;
    add_target* addtarget;
    data_d datad;
    data_l datal;
    int datal_dis_temp;
    int r;
    CurvePlot *_curvePlot=nullptr;
    QStringList pathList;//本组声音
    QTimer timer;
    QTimer timer_target;
    QTimer timer_h;
    QTimer timer_l;
    QPainter painter;
    info_t info;
    QVector<float>wav;
    QVector<data_d>data_d_v;
    QVector<info_t>target;
    int scrollArea_maxh;
    FMOD_SYSTEM *system;
    FMOD_SOUND *sound;
    FMOD_CHANNEL *channel;
    FMOD_RESULT result;
    QString strFile;
    QByteArray arr;
    bool closed;
    bool isPlaying=false;
    void Play();
    void outPut(QVector<float>&data);
    void transformPoints(QVector<float>&data, int w, int h, QVector<QPointF> &points);
    double get_angle(double x1, double y1, double x2, double y2, double vertexX, double vertexY);
private slots:
    void onTimer();  
    void target_update();
    void h_update();
    void l_update();
    void on_Slider_valueChanged(int value);
    void on_pushButton_T_clicked();
    void on_pushButton_R_clicked();
    void on_pushButton_C_clicked();
    void on_pushButton_L_clicked();
    void recdata_l(int dir,int dis);
    void recdata_d(int danger,QString info,int stardir,int enddir,int near,int far);
    void recdata_addtarget(int id,QString type,int color,int stardir,int movedir,int dis,int speed);
    void on_pushButton_D_clicked();
    void mousePressEvent(QMouseEvent *event);
    void btn_addtarget_clicked();
};

#endif // MAINWINDOW_H
